package net.easyjava.api.controller;

import com.alibaba.fastjson.JSONObject;
import net.easyjava.base.manager.HelloManager;
import net.easyjava.tools.BaseController;
import net.easyjava.tools.json.jackson.view.CustomMappingJacksonJsonpView;
import net.easyjava.tools.model.ModelBean;
import net.easyjava.tools.model.ModelConstants;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by wenxiaoning on 15/12/18.
 */
@Controller
@RequestMapping("/api/hello")
public class HelloController extends BaseController{
    @Resource
    private HelloManager helloManager;

    @RequestMapping("/world")
    @ResponseBody
    public ModelBean helloworld(
            @RequestParam String hello,
            HttpServletRequest request,HttpServletResponse response){
        ModelBean modelBean = null;
        try {
            if("11".equals(hello)){
                modelBean =  new ModelBean(paramError("hello"));
                throw new Exception();
            }

            modelBean = helloManager.helloworld(request);
        }catch (Exception e){

        }

        return model(modelBean,request,response);
    }


}
